import _ from 'lodash'
import vue from 'vue'

let loading
let needLoadingRequestCount = 0
 
 
function startLoading() {
    loading = vue.$ml.loading
    loading.show({
        lock: true,
        text: '加载中…',
    })
}

 
const tryCloseLoading = () => {
    if (needLoadingRequestCount === 0) {
        loading.hide()
    }
}
 
 
export function showFullScreenLoading() {
    if (needLoadingRequestCount === 0) {
        startLoading()
    }
    needLoadingRequestCount++
}
 
export function tryHideFullScreenLoading() {
    if (needLoadingRequestCount <= 0) return
    needLoadingRequestCount--
    if (needLoadingRequestCount === 0) {
        _.debounce(tryCloseLoading, 300)()
    }
}
